#include "DrawScenePass.h"
#include "RenderScene.h"
#include <Interface.h>

CDrawScenePass::CDrawScenePass(const std::string& vPassName, int vExecutionOrder) : IRenderPass(vPassName, vExecutionOrder)
{
}

void CDrawScenePass::initV()
{
	m_pShader = std::make_shared<CShader>("Shaders/DrawScene.vs", "Shaders/DrawScene.fs");
	glm::mat4 ModelMatrix = glm::mat4(1.0f);

	glm::vec3 LightPos = Graphics::ResourceManager::getSharedDataByName<glm::vec3>("LightPos");
	glm::vec3 ViewPos = Graphics::Camera::getMainCameraPos();

	m_pShader->activeShader();
	m_pShader->setFloatUniformValue("u_LightPos", LightPos.x, LightPos.y, LightPos.z);
	m_pShader->setFloatUniformValue("u_ViewPos", ViewPos.x, ViewPos.y, ViewPos.z);
	m_pShader->setFloatUniformValue("u_FarPlane", Graphics::Camera::getMainCameraFar());
	m_pShader->setTextureUniformValue("u_DepthMap", Graphics::ResourceManager::getSharedDataByName<std::shared_ptr<Graphics::STexture>>("DepthTexture"));
}

void CDrawScenePass::updateV()
{
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glClearColor(0, 0, 0, 1);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	m_pShader->activeShader();

	renderScene(m_pShader);

	glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
